/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.pangalacteos.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;

/**
 * Classe PROVISÓRIA que facilita o uso do hibernate
 * @author Leandro Del Sole
 */
public class HibernateUtil {
    private static SessionFactory factory;
    public static Configuration cfg;
        static {
            try {
                cfg = new AnnotationConfiguration();
                factory = new AnnotationConfiguration()
                        .configure("br/com/pangalacteos/resources/db/hibernate.cfg.xml")
                        .addAnnotatedClass(br.com.pangalacteos.modelo.Fornecedor.class)
                        .addAnnotatedClass(br.com.pangalacteos.modelo.Fatura.class)
                        .buildSessionFactory();
                 
            } catch (Exception e) {
                e.printStackTrace();
                cfg = null;
                factory = null;
            }
        }
        public static Session getSession() {
          return factory.openSession();
        }
}
